const webpack = require("webpack");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const BUILD_PATH = path.resolve(path.resolve(__dirname), 'public/dist');
const config = require('./config');

let webpackConfig = {
    entry: {},
    output: {
        path: __dirname + '/public/dist/',
        filename: '[name]-[hash].js',
        chunkFilename: '[name]-[hash].js',
        publicPath: 'http://' + config.host + ':' + config.port + '/dist/'
    },
    devtool: "inline-source-map",
    resolve: {
        // Add '.ts' and '.tsx' as resolvable extensions.
        extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
    },
    module: {
        rules: [
            { test: /\.(ts|tsx)$/, use: "ts-loader" },
            { test: /\.(png|jpg|gif|jpeg)$/, use: 'url-loader?limit=8192' },
            { test: /\.css$/, use: ['style-loader', 'css-loader'] }
        ]
    },
    // externals: {
    //     "react": "React",
    //     "react-dom": "ReactDOM"
    // },
    plugins: []
};

webpackConfig.entry.index = [];
webpackConfig.entry.main = ['./client/main/index.tsx'];
webpackConfig.entry.add = ['./client/add/index.tsx'];

webpackConfig.plugins.push(
    new HtmlWebpackPlugin({
        template: __dirname + "/client/main/index.html",
        filename: __dirname + "/public/dist/main.html",
        chunks: ['main']
    }),
    new HtmlWebpackPlugin({
        template: __dirname + "/client/add/index.html",
        filename: __dirname + "/public/dist/add.html",
        chunks: ['add']
    })
    // new webpack.optimize.UglifyJsPlugin()
);

module.exports = webpackConfig;